package com.jams.goodox.entity;

import com.jams.goodox.net.BaseEntity;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Jin on 2016/8/15.
 * Description
 */
public class BillEntity extends BaseEntity {

	private List<Parent> list;

	public List<Parent> getList() {
		return list;
	}

	public void setList(List<Parent> list) {
		this.list = list;
	}

	public static BillEntity parse(Bill bill) {
		BillEntity be = new BillEntity();

		for (Bill.DataBean.ResultListBean rlb : bill.getData().getResultList()) {
			boolean b = false;
			if (null != be) {
				if (null != be.getList()) {
					for (Parent p : be.getList()) {
						if (p.getDate().equalsIgnoreCase(rlb.getParseDate())) {
							b = true;
							p.getData().add(rlb);
						}
					}
				}
			}
			if (!b) {
				Parent pp = new Parent();
				pp.setDate(rlb.getParseDate());
				if (pp.getData() == null) {
					List<Bill.DataBean.ResultListBean> data = new ArrayList<>();
					data.add(rlb);
					pp.setData(data);
				} else {
					pp.getData().add(rlb);
				}
				if (be.getList() == null) {
					List<Parent> parent = new ArrayList<>();
					parent.add(pp);
					be.setList(parent);
				} else {
					be.getList().add(pp);
				}
			}
		}
		return be;
	}

	public static class Parent {
		private String date;
		private List<Bill.DataBean.ResultListBean> data;

		public String getDate() {
			return date;
		}

		public void setDate(String date) {
			this.date = date;
		}

		public List<Bill.DataBean.ResultListBean> getData() {
			return data;
		}

		public void setData(List<Bill.DataBean.ResultListBean> data) {
			this.data = data;
		}
	}


}
